package org.mikhaylov.cp.web.command.redirect;

import javax.servlet.http.HttpServletRequest;

import org.mikhaylov.cp.service.command.ServiceCommandContainer;
import org.mikhaylov.cp.web.command.WebCommand;
import org.mikhaylov.cp.web.storage.Path;

public class MyInvWebCommand extends WebCommand {

	private static final long serialVersionUID = 4010719575892841923L;

	@Override
	protected boolean checkParams(HttpServletRequest request) {
		if (request.getSession().getAttribute("user") == null) {
			forward = Path.PAGE_ERROR;
			request.setAttribute("errorMessage", "Authorization problem");
			return false;
		}
		return true;
	}

	@Override
	protected boolean extractParams(HttpServletRequest request) {
		return true;
	}

	@Override
	protected void process(HttpServletRequest request) {
		request.setAttribute("user", request.getSession().getAttribute("user"));
		forward = Path.PAGE_MY_INVENTORIES;
		ServiceCommandContainer.get("getUserInventories").execute(request, null);
	}

}
